﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using ColorLife.Core.Helper;
namespace DLUProject.Domain
{
    public class ModuleParams
    {
        public bool ShowTitle { get; set; }
        public int MaxItem { get; set; }
        public bool ShowHit { get; set; }
        public bool ShowDate { get; set; }
        public bool ShowAuthor { get; set; }
        public static ModuleParams GetModuleParams(string xmlString)
        {
            if (xmlString != null && xmlString != "" && xmlString.IsValidXml())
            {
                ModuleParams moduleParams = new ModuleParams();
                using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
                {
                    reader.ReadToFollowing("showTitle");
                    moduleParams.ShowTitle = reader.ReadElementContentAsString().ToBool();
                    reader.ReadToFollowing("maxItem");
                    moduleParams.MaxItem = reader.ReadElementContentAsString().ToInt();

                    reader.ReadToFollowing("showHit");
                    moduleParams.ShowHit = reader.ReadElementContentAsString().ToBool();

                    reader.ReadToFollowing("showDate");
                    moduleParams.ShowDate = reader.ReadElementContentAsString().ToBool();

                    reader.ReadToFollowing("showAuthor");
                    moduleParams.ShowAuthor = reader.ReadElementContentAsString().ToBool();

                    return moduleParams;
                }
            }
            else
            {
                return null;
            }
        }
    }
}
